package cn.wh.pay.type.ltzf.config;

import cn.wh.pay.configuration.PayConfig;
import lombok.Getter;
import okhttp3.logging.HttpLoggingInterceptor;

/**
 * @Author wh
 * @Description
 * @Date 2024/4/19 15:26
 * @Version 1.0
 **/
@Getter
public class LtzfConfiguration {
    private final String apiHost;

    // 开发者ID
    private final String appId;
    // 商户号ID
    private final String merchantId;
    // 商户秘钥
    private final String partnerKey;

    /**
     * 通过构造的方式注入值
     * @param payConfig 配置的支付
     */
    public LtzfConfiguration(PayConfig payConfig) {
        this.apiHost = payConfig.getApiHost();
        this.appId = payConfig.getAppId();
        this.merchantId = payConfig.getMerchantId();
        this.partnerKey = payConfig.getPartnerKey();
        this.connectTimeout = payConfig.getConnectTimeout();
        this.writeTimeout = payConfig.getWriteTimeout();
        this.readTimeout = payConfig.getReadTimeout();
        this.level = getLevel(payConfig.getLevel());
    }
    private HttpLoggingInterceptor.Level level;

    private long connectTimeout;

    private long writeTimeout;

    private long readTimeout;

    public static HttpLoggingInterceptor.Level getLevel(String level) {
        switch (level.toUpperCase()) {
            case "BASIC":
                return HttpLoggingInterceptor.Level.BASIC;
            case "HEADERS":
                return HttpLoggingInterceptor.Level.HEADERS;
            case "BODY":
                return HttpLoggingInterceptor.Level.BODY;
            default:
                return HttpLoggingInterceptor.Level.NONE;
        }
    }

}
